import { Application } from 'egg';
import { User } from '../model/User';

export default (app: Application) => {
    return {
        schedule: {
            interval: app.config.notificationInterval,
            type: 'all',
            immediate: true,
        },
        async task(ctx) {
            const resultUser: any = await app.model.User.findAll<User>({
                attributes: ['user_openId'],
                where: { is_news: '1' }
            });
            const template_id=ctx.app.config.templateMessageId.noticeMessage;
            const baseUrl=ctx.app.config.baseUrl;
            for (let i = 0; i < resultUser.length; i++) {
                const user_openId = resultUser[i].user_openId;
                const data = {};
                const reuslt = await ctx.service.templateService.sendWechatMsg(baseUrl+'api/wx/wxPlatform/directToGetCode', data, user_openId, template_id);
                app.logger.info(reuslt);
            }
            console.log(ctx);
        },
    };
};
